home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archivers / LZX_Repack / LHA2LZX < prev    next >
Text File  |  1996-09-26  |  6KB  |  173 lines

  1. /*
  2.     $VER: LHA-LZX REPACK V2.04b  Updated by Christer Bjarnemo (1995/12/17)
  3.  */
  4.  
  5. TempDir        = 'HD1:TRASHCAN/'
  6. Mode        = '3'
  7. Priority    = -1
  8. VirtualDisk    = 'FM0:'
  9.  
  10. /*************************************************/
  11. /* I recommend you leave it alone from here. :-) */
  12. /*************************************************/
  13.  
  14. Arg Dir arg1 arg2 arg3 arg4
  15.  
  16. forcelzx = 0
  17. LZXStore = TempDir
  18. TempDir = TempDir'_LZX_TEMP/'
  19. If ~EXISTS(TempDir) then address COMMAND 'makedir 'left(TempDir,length(TempDir)-1)
  20.  
  21. PATTERN = '.LZH|.LHA|.ZIP|.ARJ|.ARC|.ZOO|.GZ|.Z'
  22.  
  23. say 
  24. say 'LHA-LZX repacker 2.04b updated by Christer Bjarnemo 1995-12-17.'
  25. say 'Original program by Mat Bettinson of the Plot Hatching Factory.'
  26. say
  27.  
  28. if upper(arg1) = 'FORCELZX' | upper(arg2)='FORCELZX' | upper(arg3)='FORCELZX' | upper(arg4)='FORCELZX' then ForceLZX = 1
  29. if upper(arg1) = 'KEEPOLD' | upper(arg2)='KEEPOLD' | upper(arg3)='KEEPOLD' | upper(arg4)='KEEPOLD' then KEEPOLD = 'YES'
  30. if upper(arg1) = 'ONLYLHA' | upper(arg2)='ONLYLHA' | upper(arg3)='ONLYLHA' | upper(arg4)='ONLYLHA' then PATTERN = '.LZH|.LHA'
  31. if upper(arg1) = 'DMS' | upper(arg2)='DMS' | upper(arg3)='DMS' | upper(arg4)='DMS' then PATTERN = PATTERN'|.DMS'
  32.  
  33. If Dir = '?' | Dir = '/?' | Dir = '-?' | Dir = '' then signal Usage
  34.  
  35. If dir = '22'x'22'x then do
  36.     dir = '22'x'22'x
  37.     address command 'assign CDIR: 'dir
  38.     dir = 'CDIR:'
  39.     end
  40.  
  41. If ~EXISTS(Dir) then signal Usage
  42. say
  43. Call Pragma('S',50000)
  44. If right(Dir,1) ~= '/' & right(Dir,1) ~= ':' then Dir = Dir'/'
  45. Address COMMAND 'Assign REPACK: 'Tempdir
  46. Call Pragma('D','REPACK:')
  47. Address COMMAND 'List 'Dir' PAT #?('PATTERN') FILES LFORMAT "%n %c" >t:LHA-LZX.temp'
  48. Call Open(list,'t:LHA-LZX.temp','R')
  49. BSave = 0
  50. DO forever
  51.  Line = ReadLN(list)
  52.  File = strip(word(line,1)) ; Comment = strip(word(line,2)) ; Comment = Strip(Comment,'B','"')
  53.  IF EOF(list) then break
  54.  NewFile = Left(File,Length(file)-length(ext(file)))'LZX'
  55.  
  56.  say 'Converting file: 'File
  57.  Address COMMAND 'Delete >NIL: REPACK:#? ALL FORCE'
  58.  Call Open(ts,Dir||file) ; Lhasize = Seek(ts,0,'E') ; Call Close(ts)
  59.  
  60. /* Now we are going to extract the archive */
  61.  
  62. if ext(file)='LHA' then Address COMMAND 'LHA -a -F -M -P'Priority' x 'Dir||File' #? REPACK:'
  63. if ext(file)='LZH' then Address COMMAND 'LHA -a -F -M -P'Priority' x 'Dir||File' #? REPACK:'
  64. if ext(file)='ZIP' then Address COMMAND 'UnZip 'Dir||File' -d REPACK:'
  65.  
  66. if ext(file)='DMS' then do
  67.     Address command 'format >NIL: <NIL: drive 'VirtualDisk' name Empty quick noicons'
  68.     Address COMMAND 'unDMS <NIL: write 'Dir||File' to 'VirtualDisk' NOPAUSE NOTEXT'
  69.         Address COMMAND 'Copy >NIL: FM0:#? all to REPACK:'
  70.     end
  71.  
  72. if ext(file)='ARJ' then Address COMMAND 'UnARJ x 'Dir||File' REPACK:'
  73. if ext(file)='ARC' then do
  74.     Pragma('D','REPACK:')
  75.     Address COMMAND 'ARC x 'Dir||File
  76.     end
  77. if ext(file)='ZOO' then do
  78.     Pragma('D','REPACK:')
  79.     Address COMMAND 'ZOO eq/ 'Dir||File
  80.     end
  81. if ext(file)='GZ'  then Address COMMAND 'GZIP 'Dir||left(file,length(file)-1-length(ext(file)))' -cdN >REPACK:'left(file,length(file)-1-length(ext(file)))
  82. if ext(file)='Z' then Address COMMAND 'uncompress 'Dir||left(file,length(file)-1-length(ext(file)))' -c >REPACK:'left(file,length(file)-1-length(ext(file)))
  83.  
  84.  if RC ~= 0 then do
  85.     say ''
  86.     say 'WARNING! Something went wrong while unpacking 'file'.'
  87.     say 'The 'ext(file)' file could be corrupt, or (hopefully) there wasnt enough'
  88.     say 'space left on your hd/ramdisk.'
  89.     call writech(stdout,'Do you want to continue? (some files might be LOST forever) (y/N) ')
  90.     parse pull choice
  91.     if upper(choice) ~= 'Y' then do
  92.         exit(20)
  93.         end
  94.     end
  95.  
  96.  Address COMMAND 'LZX -r -e -M5000 -'Mode' -P'Priority' -F a 'LZXStore||NewFile' REPACK:#?'
  97.  
  98.  if RC ~= 0 then do
  99.     fel = 1
  100.     say ''
  101.     say 'WARNING! Something went wrong while packing 'LZXStore||newfile'.'
  102.     call writech(stdout,'Do you want to continue? (keeps the 'ext(file)' file) (y/N) ')
  103.  
  104.     parse pull choice
  105.     if upper(choice) ~= 'Y' then do
  106.         Address COMMAND 'Delete >NIL: 'LZXStore||newfile
  107.         say 'The original file 'file' is untouched :-)'
  108.         exit(20)
  109.         end
  110.     end
  111.  
  112. if fel ~= 1 then do
  113.  Call Open(ts,LZXStore||NewFile) ; Lzxsize = Seek(ts,0,'E') ; Call Close(ts)
  114.  Diff = Lhasize - Lzxsize
  115.  If Diff > 0 | ForceLZX then DO
  116.   if KEEPOLD ~= 'YES' then Address COMMAND 'Delete >NIL: 'Dir||File
  117.   If Comment ~= '' then Address COMMAND 'Filenote 'LZXStore||NewFile' "'Comment'"'
  118.   Address COMMAND 'Copy 'LZXStore||newfile' to 'dir
  119.  
  120.  if RC ~= 0 then do
  121.     say ''
  122.     say 'WARNING! Something went wrong while copying 'newfile' to 'dir'.'
  123.     call writech(stdout,'Do you want to continue? (the archive will be LOST forever) (y/N) ')
  124.     parse pull choice
  125.     if upper(choice) ~= 'Y' then do
  126.         say 'You should copy the file 'LZXStore||newfile' to a SAFE place.'
  127.         exit(20)
  128.         end
  129.     end
  130.  
  131.   Address COMMAND 'Delete >NIL: 'LZXStore||newfile
  132.   say '* 'Diff' bytes saved on this archive!' ; say
  133.   END
  134.  ELSE DO
  135.   Address COMMAND 'Delete >NIL: 'LZXStore||Newfile
  136.     say '* 'ext(file)' file 'ABS(Diff)' bytes larger than LZX. Keeping 'ext(file)'...' ; say
  137.   Diff = 0
  138.   END
  139.  BSave = BSave + Diff
  140. end
  141. else say '* Keeping 'ext(file)'...'
  142. end
  143.  
  144. Call Close(list)
  145. Address COMMAND 'Delete >NIL: REPACK:#? ALL FORCE'
  146. Address COMMAND 'Assign REPACK: REMOVE'
  147. Address COMMAND 'Assign CDIR: REMOVE'
  148.  
  149. say
  150. say ' *** LHA-LZX Repacker finished. 'Bsave' bytes saved in this dir. ***'
  151. say
  152. EXIT
  153.  
  154. Usage:
  155. say 'Usage: LHA2LZX <Directory> [options]'
  156. say
  157. say '  ForceLZX  Allways keep the LZX file even if the LHA file is smaller'
  158. say '  KeepOLD   Keep both LhA/ZIP and the LZX file'
  159. say '  OnlyLHA   Only repack LHA files'
  160. say '  DMS       Repack DMS archives'
  161. say
  162. say 'HINT: Replace <directory> with "" if you want to repack current dir.'
  163. say
  164. EXIT
  165.  
  166. ext: procedure
  167.   arg filename
  168.   do i=1 to length(filename)
  169.      if upper(substr(filename,length(filename)-i,1)) = '.' then break
  170.   end
  171.      extension = upper(right(filename,i))
  172. return(extension)
  173.